<%@page import="com.softeem.sss.dto.FileInfo"%>
<%@page import="java.util.List"%>
<%@page import="com.softeem.sss.dao.FileInfoDAO"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="doPagination.jsp" %>
<%
	//获取排序依据
	String sortColumn = request.getParameter("sc");
	sortColumn = sortColumn == null ? "" : sortColumn;
	FileInfoDAO fdao = new FileInfoDAO();
	//查询所有
	List<FileInfo> files = fdao.findAll(sortColumn);
	
	//获取总记录数
	totalNum = files.size();
	//计算总页数
	if(totalNum % pageSize == 0){
		totalPage = totalNum / pageSize;
	}else{
		totalPage = totalNum / pageSize + 1;
	}
	//限制尾页
	if(currentPage > totalPage){
		currentPage = totalPage;
	}
	//限制首页
	if(currentPage < 1){
		currentPage = 1;
	}
	//截取数组
	int start = (currentPage-1)*pageSize;
	int end = currentPage * pageSize;
	end = end > totalNum ? totalNum : end;
	//截取数组
	files = files.subList(start , end);
	
	//保存分页信息
	request.setAttribute("cp", currentPage);
	request.setAttribute("tp", totalPage);
	request.setAttribute("tn", totalNum);
	
	//将资源集合存储到request范围中
	request.setAttribute("files", files);
	request.setAttribute("link","doList.jsp?sc="+sortColumn+"&");
	request.getRequestDispatcher("list.jsp").forward(request, response);
%>
